package com.sky.edumanageapi.comment.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sky.edumanageapi.comment.dao.repository.CommentRepository;
import com.sky.edumanageapi.comment.mapper.CommentMapper;
import com.sky.edumanageapi.comment.pojo.dto.CommentParam;
import com.sky.edumanageapi.comment.pojo.entity.Comment;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Repository
public class CommentRepositoryImpl implements CommentRepository {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public List<Comment> getCommentListByCourseId(Integer courseId) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("course_id",courseId);


        return commentMapper.selectList(queryWrapper);
    }

    @Override
    public void insert(CommentParam commentParam) {

        Comment comment =new Comment();
        BeanUtils.copyProperties(commentParam,comment);

        comment.setCreateTime(new Date());

        commentMapper.insert(comment);
    }

    @Override
    public List<Comment> getCommentListByUserId(Integer userId) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("user_id",userId);


        return commentMapper.selectList(queryWrapper);
    }
}
